package com.erlang4j.api.exceptions;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.erlang4j.internal.exceptions.Erlang4jException;
import com.erlang4j.internal.exceptions.Erlang4jExceptionConstants;

/** Thrown if there is any exception during send */
public class Erlang4jCannotSendException extends Erlang4jException {

	public Erlang4jCannotSendException(IOException e, Object pidOrName, Object... data) {
		super(e, Erlang4jExceptionConstants.cannotSendExceptionKey, makeArray(pidOrName, data));
	}

	private static Object[] makeArray(Object pidOrName, Object[] data) {
		List<Object> list = new ArrayList<Object>();
		list.add(pidOrName);
		list.addAll(Arrays.asList(data));
		return list.toArray();
	}

}
